//
//  AnimationExampleViewController.m
//  SDKSample
//
//  Created by 小肥羊 on 15/11/16.
//  Copyright © 2015年 Zhu‘s Game House. All rights reserved.
//

#import "AnimationExampleViewController.h"
#import "XFYAnimationTool.h"

@interface AnimationExampleViewController ()

@end

@implementation AnimationExampleViewController
#pragma mark - 惰性初始化
- (UIView *)testSuperView
{
    if (!_testSuperView) {
        _testSuperView = [[UIView alloc] initWithFrame:CGRectMake(50, 240, 120, 120)];
        [_testSuperView addSubview:self.testView];
        [_testSuperView addSubview:self.testView2];
    }
    return _testSuperView;
}
- (UIView *)testView
{
    if (!_testView) {
        _testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
        [_testView setBackgroundColor:[UIColor grayColor]];
    }
    return _testView;
}
- (UIView *)testView2
{
    if (!_testView2) {
        _testView2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)];
        [_testView2 setBackgroundColor:[UIColor yellowColor]];
    }
    return _testView2;
}

#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:self.testSuperView];
}
- (IBAction)click1:(id)sender {
    //演员初始化
    CALayer *scaleLayer = self.testSuperView.layer;
    
    //设定剧本
    CABasicAnimation *scaleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    scaleAnimation.fromValue = [NSNumber numberWithFloat:1.0];
    scaleAnimation.toValue = [NSNumber numberWithFloat:1.2];
    scaleAnimation.autoreverses = YES;
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.repeatCount = MAXFLOAT;
    scaleAnimation.duration = 0.8;
    
    //开演
    [scaleLayer addAnimation:scaleAnimation forKey:@"scaleAnimation"];
}
- (IBAction)click2:(id)sender {
    [self.testSuperView.layer removeAllAnimations];
}
- (IBAction)click3:(id)sender {
    [self.playerView.layer addAnimation:[[XFYAnimationTool sharedAnimationTool] openAnimationWithView:self.playerView] forKey:@"animation"];
}
- (IBAction)click4:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
        [UIView setAnimationDelay:0.8];//配置动画时延
        self.testSuperView.center = CGPointMake(self.view.bounds.size.width/2,self.view.bounds.size.height/2);//可以对多个view进行我们想要的动画配置
    } completion:^(BOOL finished) {
        //执行完后走这里的代码块
        NSLog(@"动画结束");
    }];
//    [CATransaction begin];
//    [CATransaction setAnimationDuration:0.2];
//    [CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
//    [CATransaction setCompletionBlock:^{
//        NSLog(@"动画结束");
//    }];
//    [self.playerView.layer addAnimation:[[XFYAnimationTool sharedAnimationTool] pushAnimationWithView:self.playerView] forKey:@"animation"];
//    [CATransaction commit];
}

- (IBAction)click5:(id)sender {
//    [[XFYAnimationTool sharedAnimationTool] animationWithView:self.testView2 Type:XFYAnimationTypeReveal FromType:kCATransitionFromBottom];
    [[XFYAnimationTool sharedAnimationTool] animationWithView:self.testSuperView Type:XFYAnimationTypeCube FromType:kCAAlignmentLeft PlayTime:2.0];
    [self.testSuperView bringSubviewToFront:self.testView];
}
- (IBAction)click6:(id)sender {
//    [[XFYAnimationTool sharedAnimationTool] animationWithView:self.testView2 AnimationTransition:UIViewAnimationTransitionFlipFromRight];
    [[XFYAnimationTool sharedAnimationTool] animationWithView:self.testSuperView AnimationTransition:UIViewAnimationTransitionFlipFromLeft PlayTime:2.0 DelayTime:0.7];
    [self.testSuperView bringSubviewToFront:self.testView2];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
